<?php
function echoStat($stat, $positionStat) {
	if ($stat == $positionStat) {
		echo "  <td>" . getEchoValue($stat) . "</td>\n";
	} else {
		echo "  <td><b>" . getEchoValue($stat) . "</b></td>\n";
	}
}

function echoPlayerRow($player, $id, $position, $usesExps) {

	if (!$player) {
		echo "<tr align=center>\n  <td>" . $id . "</td>\n  <td align=left>&nbsp;</td>\n  <td align=left>&nbsp;</td>\n  <td>&nbsp;</td>\n  <td>&nbsp;</td>\n  <td>&nbsp;</td>\n  <td>&nbsp;</td>\n  <td align=left>&nbsp;</td>\n  <td>&nbsp;</td>\n  <td>&nbsp;</td>\n  <td>&nbsp;</td>\n  <td>&nbsp;</td>\n  <td>&nbsp;</td>\n  <td>&nbsp;</td>\n  <td>&nbsp;</td>\n  <td align=\"right\">&nbsp;</td>\n</tr>\n";
	} else {
		echo "<tr align=center>\n";
		echo "  <td>" . $id . "</td>\n";
		echo "  <td align=left>" . getEchoValueShrink($player->name, 15) . "</td>\n";
		echo "  <td align=left>" . getEchoValue($player->position) . "</td>\n";
		if (!$position) {
			echo "  <td>" . getEchoValue($player->ma) . "</td>\n";
			echo "  <td>" . getEchoValue($player->st) . "</td>\n";
			echo "  <td>" . getEchoValue($player->ag) . "</td>\n";
			echo "  <td>" . getEchoValue($player->av) . "</td>\n";
		} else {
			echoStat($player->ma, $position->ma);
			echoStat($player->st, $position->st);
			echoStat($player->ag, $position->ag);
			echoStat($player->av, $position->av);
		}
		echo "  <td align=left>" . getEchoValueShrink($player->skills, 20) . "</td>\n";
		echo "  <td>" . getEchoValue($player->getInjuries()) . "</td>\n";
		echo "  <td>" . getEchoValue($player->completions) . "</td>\n";
		echo "  <td>" . getEchoValue($player->tds) . "</td>\n";
		echo "  <td>" . getEchoValue($player->interceptions) . "</td>\n";
		echo "  <td>" . getEchoValue($player->casualties) . "</td>\n";
		if ($usesExps) {
			echo "  <td>" . getEchoValue($player->exps) . "</td>\n";
		} else {
			echo "  <td>" . getEchoValue($player->mvps) . "</td>\n";
		}
		echo "  <td>" . getEchoValue($player->getSPPS()) . "</td>\n";
		echo "  <td align=\"right\">" . getEchoValue($player->cost) . "k</td>\n";
		echo "</tr>\n";
	}
}
include ("includes/init.php");

$team = $teams->getTeam($_GET["id"]);
$wonSeasons = $sd->findWonSeasons($team->id);

echo<<< EOQ
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>$team->name</title>
    <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
    <meta name="description" content="$defaultPageTitle">
    <meta name="keywords" content="bloodbowl, blood bowl, league, games workshop, games, bbl, blood, bowl, $keywords">
    <meta http-equiv="Cache-Control" content="max-age=0">
    <meta http-equiv="Pragma" content="no-cache">
  </head>
  <body bgColor="white" text="black" >
    <center>
        <h1>$team->name</h1>
        <table border="1" width="100%">
          <tr >
            <th>#</th>
            <th>Player Name</th>
            <th>Position</th>
            <th>ma</th>
            <th>st</th>
            <th>ag</th>
            <th>av</th>
            <th>Skills</th>
            <th>inj</th>
            <th>cp</th>
            <th>td</th>
            <th>in</th>
            <th>cs</th>
EOQ;
if ($team->usesExp) {
	echo<<< EOQ
            <th>exp</th>
EOQ;
} else {
	echo<<< EOQ
            <th>mvp</th>
EOQ;
}
echo<<< EOQ
            <th>spps</th>
            <th>Cost</th>
          </tr>

EOQ;
$i = 0;
$totalCmps = 0;
$totalTds = 0;
$totalInts = 0;
$totalCas = 0;
$totalMVPS = 0;
for ($i = 1; $i < 17; $i++) {
	$player = $team->getPlayer($i);
	echoPlayerRow($player, $i, !$player ? false : $team->race->getPosition($player->position), $team->usesExp);
	if ($player != false) {
		$totalCmps += $player->completions;
		$totalTds += $player->tds;
		$totalInts += $player->interceptions;
		$totalCas += $player->casualties;
		if ($team->usesExp) {
			$totalMVPS += $player->exps;
		} else {
			$totalMVPS += $player->mvps;
		}
	}
}
echo<<< EOQ
          <tr>
            <td colSpan="7">&nbsp;</td>
            <td colSpan="2" align="center"><font size="-1">Totals</font></td>
            <td align="center"><font size="-1">$totalCmps</font></td>
            <td align="center"><font size="-1">$totalTds</font></td>
            <td align="center"><font size="-1">$totalInts</font></td>
            <td align="center"><font size="-1">$totalCas</font></td>
            <td align="center"><font size="-1">$totalMVPS</font></td>
            <td align="center"><font size="-1">
EOQ;
echo $team->getSPPsTotal() . "</font></td>\n<td align=\"right\"><font size=\"-1\">" . $team->getPlayerCostTotal() . "k</font></td>\n</tr>\n";
$rerollCost = $team->rerolls * $team->race->rerollCost;
$ffCost = $team->fanFactor * 0;
$coachCost = $team->coaches * 10;
$coachName = $team->coach->name;
$cheerCost = $team->cheerleaders * 10;
$apocCost = $team->apothecary * 50;
$tr = $team->getTR();
$totalCost = $team->getTotalCost();
$race = $team->race;
echo<<< EOQ
          <tr align="center">
            <td align="right"  colSpan="2">Race:</td>
            <td colSpan=5>$race->name</td>
            <td align="right"  colSpan="2">Re-Rolls:</td>
            <td colSpan="2">$team->rerolls</td>
            <td  colSpan="4">x $race->rerollCost k =</td>
            <td align="right">$rerollCost k</td></tr>
          <tr align="middle">
            <td align="right"  colSpan="2">Coach:</td>
            <td colSpan=5>$coachName</td>
            <td align="right"  colSpan="2">Fan Factor:</td>
            <td colSpan="2">$team->fanFactor</td>
            <td  colSpan="4">x 10 k =</td>
            <td align="right">$ffCost k</td></tr>
          <tr align=middle>
            <td align="right"  colSpan="2">Treasury:</td>
            <td colSpan=5>$team->treasury</td>
            <td align="right"  colSpan="2">Assistant Coaches:</td>
            <td colSpan="2">$team->coaches</td>
            <td  colSpan="4">x 10 k =</td>
            <td align="right">$coachCost k</td></tr>
          <tr align=middle>
            <td align="right"  colSpan="2">Money Lent:</td>
            <td colSpan=5>$team->moneyLent</td>
            <td align="right"  colSpan="2">Cheerleaders:</td>
            <td colSpan="2">$team->cheerleaders</td>
            <td  colSpan="4">x 10 k =</td>
            <td align="right">$cheerCost k</td></tr>
          <tr align=middle>
            <td align="right"  colSpan="2">Money Borrowed:</td>
            <td colSpan=5>$team->moneyBorrowed</td>
            <td align="right"  colSpan="2">Apothecary:</td>
            <td colSpan="2">$team->apothecary</td>
            <td  colSpan="4">x 50 k =</td>
            <td align="right">$apocCost k</td></tr>
          <tr align=middle>
            <td align="right"  colSpan="2">Last Update:</td>
            <td colSpan=5>$team->lastUpdate</td>
            <td align="right" rowspan="2"  colSpan=8>TOTAL COST OF TEAM:</td>
            <td align="right" rowspan="2">$totalCost k</td>
          <tr align=middle>
            <td align="right"  colSpan="2">Team Value:</td>
            <td colSpan=5><b>$tr</b> k</td>
          </tr>
          </tbody>
        </table>
    </center>
EOQ;
	foreach($wonSeasons as $wonSeason) {
echo<<< EOQ
        <br />Winner $wonSeason->season, $wonSeason->imageText
EOQ;
	}				
echo<<< EOQ
    <br />$team->comments
EOQ;
	// output all the inducements available
	$chefCost = 300;
	$bribeCost = 100;
	if ($race->id == 7) {
	    $chefCost = 100;
	}
	if ($race->id == 38) {
	    $chefCost = 50;
	}
	if ($race->id == 37) {
	    $bribeCost = 50;
	}
echo<<< EOQ
	<h4>Available Inducements</h4>
	\$50,000 Bloodweiser Babes (2)  
	<br />\$$bribeCost,000 Bribes (3)  
	<br />\$100,000 Rerolls (4)  
	<br />\$100,000 Wandering Apothecaries (2) OR Igor (1)
	<br />\$150,000 Wizard 
	<br />\$$chefCost,000 Master Chef  
EOQ;
	foreach($race->positions as $position) {
	    if ($position->isJourneyman()) {
	        continue;
	    }
	    if ($position->isStar()) {
echo<<< EOQ
	<br />\$$position->cost,000 $position->position ($position->ma $position->st $position->ag $position->av $position->skillsStr) 
EOQ;
	    } else {
	    	$mercCost = $position->cost + 30;
	    	$mercSkillCost = $position->cost + 30 + 50;
echo<<< EOQ
	<br />\$$mercCost,000 (\$$mercSkillCost,000) Mercenary $position->position (with skill) 
EOQ;
	    }
	}	 
	
echo<<< EOQ
  </body>
</html>
EOQ;
?>